package demo.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.extension.Adaptive;
import org.apache.dubbo.rpc.*;
import org.springframework.util.StopWatch;

/**
 * @author m0v1
 * @date 2021年09月22日 10:57 下午
 */
// 激活扩展点,通过group属性指定该扩展点使用范围
@Activate(group = {CommonConstants.CONSUMER,CommonConstants.PROVIDER})
public class InvokeFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        StopWatch stopWatch = new StopWatch("record time of method:" + invocation.getMethodName());
        stopWatch.start();
        try {
            return invoker.invoke(invocation);
        } finally {
            stopWatch.stop();
            System.out.println(stopWatch.prettyPrint());
        }
    }
}
